#!/bin/bash
source /etc/profile
. $BEETLE_SHELL_PATH/error.sh

#版本号
version=$1

# 分支名
branch=$2

codePath=/usr/local/beetle/code/matrix-ui
workPath=/usr/local/nginx
configPath=/usr/local/beetle/config/matrix-ui
bakPath=/usr/beetle/appbak/matrix-ui
bakName=matrix-ui
projectName=matrix-ui

bash $BEETLE_SHELL_PATH/git_checkout.sh ${codePath} ${branch} || error_exit

bash $BEETLE_SHELL_PATH/bak.sh ${workPath} ${projectName} ${bakPath} ${bakName} || error_exit

cd ${codePath} || error_exit

cp -Rf `ls |grep -v config/config.js` ${workPath}/${projectName}/ || error_exit

cp -Rf ${configPath}/* ${workPath}/${projectName}/ || error_exit


if [ ! ${version} ]
then
	version=`date +%Y%m%d%H%M%S`
fi

cd ${workPath}/${projectName} || error_exit
mv index.html index.html.bak || error_exit
mv index.html.online index.html || error_exit
sed -i "s/^.*var matrix_global_random.*$/var matrix_global_random = '?v${version}';/" index.html  || error_exit